/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package TapestryModel.impl;

import TapestryModel.ContentData;
import TapestryModel.Page;
import TapestryModel.TapestryModelPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Content Data</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link TapestryModel.impl.ContentDataImpl#isPersist <em>Persist</em>}</li>
 *   <li>{@link TapestryModel.impl.ContentDataImpl#getPage <em>Page</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class ContentDataImpl extends DataImpl implements ContentData {
    /**
     * The default value of the '{@link #isPersist() <em>Persist</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isPersist()
     * @generated
     * @ordered
     */
    protected static final boolean PERSIST_EDEFAULT = false;

    /**
     * The cached value of the '{@link #isPersist() <em>Persist</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isPersist()
     * @generated
     * @ordered
     */
    protected boolean persist = PERSIST_EDEFAULT;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected ContentDataImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    protected EClass eStaticClass() {
        return TapestryModelPackage.Literals.CONTENT_DATA;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public boolean isPersist() {
        return persist;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setPersist(boolean newPersist) {
        boolean oldPersist = persist;
        persist = newPersist;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.CONTENT_DATA__PERSIST, oldPersist, persist));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public Page getPage() {
        if (eContainerFeatureID != TapestryModelPackage.CONTENT_DATA__PAGE) return null;
        return (Page)eContainer();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain basicSetPage(Page newPage, NotificationChain msgs) {
        msgs = eBasicSetContainer((InternalEObject)newPage, TapestryModelPackage.CONTENT_DATA__PAGE, msgs);
        return msgs;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setPage(Page newPage) {
        if (newPage != eInternalContainer() || (eContainerFeatureID != TapestryModelPackage.CONTENT_DATA__PAGE && newPage != null)) {
            if (EcoreUtil.isAncestor(this, newPage))
                throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
            NotificationChain msgs = null;
            if (eInternalContainer() != null)
                msgs = eBasicRemoveFromContainer(msgs);
            if (newPage != null)
                msgs = ((InternalEObject)newPage).eInverseAdd(this, TapestryModelPackage.PAGE__DATA, Page.class, msgs);
            msgs = basicSetPage(newPage, msgs);
            if (msgs != null) msgs.dispatch();
        }
        else if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.CONTENT_DATA__PAGE, newPage, newPage));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                if (eInternalContainer() != null)
                    msgs = eBasicRemoveFromContainer(msgs);
                return basicSetPage((Page)otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                return basicSetPage(null, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
        switch (eContainerFeatureID) {
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                return eInternalContainer().eInverseRemove(this, TapestryModelPackage.PAGE__DATA, Page.class, msgs);
        }
        return super.eBasicRemoveFromContainerFeature(msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_DATA__PERSIST:
                return isPersist() ? Boolean.TRUE : Boolean.FALSE;
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                return getPage();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_DATA__PERSIST:
                setPersist(((Boolean)newValue).booleanValue());
                return;
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                setPage((Page)newValue);
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_DATA__PERSIST:
                setPersist(PERSIST_EDEFAULT);
                return;
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                setPage((Page)null);
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.CONTENT_DATA__PERSIST:
                return persist != PERSIST_EDEFAULT;
            case TapestryModelPackage.CONTENT_DATA__PAGE:
                return getPage() != null;
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public String toString() {
        if (eIsProxy()) return super.toString();

        StringBuffer result = new StringBuffer(super.toString());
        result.append(" (persist: ");
        result.append(persist);
        result.append(')');
        return result.toString();
    }

} //ContentDataImpl
